// 共享的API接口类型定义

export interface User {
  id: string;
  username: string;
  email: string;
  nickname?: string;
  avatar?: string;
  bio?: string;
  status: 'online' | 'offline' | 'away';
  lastSeen: Date;
}

export interface Message {
  id: string;
  senderId: string;
  receiverId: string;
  type: 'text' | 'image' | 'voice' | 'file' | 'system';
  content: string;
  attachments?: string[];
  status: 'sending' | 'sent' | 'delivered' | 'read';
  isGroup: boolean;
  groupId?: string;
  replyTo?: string;
  readBy: string[];
  createdAt: Date;
  updatedAt: Date;
}

export interface Group {
  id: string;
  name: string;
  description?: string;
  avatar?: string;
  ownerId: string;
  members: Array<{
    userId: string;
    role: 'admin' | 'member';
  }>;
  admins: string[];
  isPublic: boolean;
  maxMembers: number;
  announcement?: string;
  createdAt: Date;
  updatedAt: Date;
}

export interface Conversation {
  id: string;
  type: 'user' | 'group';
  name: string;
  avatar?: string;
  lastMessage?: Message;
  unreadCount: number;
  lastActivity: Date;
}

export interface LoginRequest {
  username: string;
  password: string;
}

export interface RegisterRequest {
  username: string;
  email: string;
  password: string;
  nickname?: string;
}

export interface AuthResponse {
  access_token: string;
  user: User;
}

export interface SendMessageRequest {
  receiverId: string;
  type: Message['type'];
  content: string;
  isGroup?: boolean;
  attachments?: string[];
}

export interface SocketEvents {
  'newMessage': Message;
  'typing': { userId: string; isTyping: boolean };
  'friendOnline': { userId: string; status: string; lastSeen: Date };
  'friendOffline': { userId: string; status: string; lastSeen: Date };
  'messageRead': { messageId: string; readBy: string };
}

export interface ApiResponse<T = any> {
  success: boolean;
  data?: T;
  message?: string;
  error?: string;
}
